//
//  YDBuySelectedRateCell.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/15.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDBuySelectedRateCell.h"
#import "YDLossRateModel.h"


@interface YDBuySelectedRateCell()
//分割线
@property (nonatomic , weak) UIView *lineView;

//止损止盈率
@property (nonatomic , weak) UILabel *rateLabel;

//选中之后的图片
@property (nonatomic , weak) UIImageView *selectedImage;

@end

@implementation YDBuySelectedRateCell


-(void)setModel:(YDLossRateModel *)model
{
    _model = model;
    
    //self.rateLabel.text = model.point;
    self.rateLabel.text = [NSString stringWithFormat:@"-%.1f%%",model.point.floatValue * 100];
    
    
    if (model.isSelected) {
        
        self.selectedImage.hidden = NO;
        self.rateLabel.textColor = [UIColor colorWithHexString:leafyGreen];
    }else{
        
        self.selectedImage.hidden = YES;
        self.rateLabel.textColor = NumberColor(104, 114, 132);
    }
    
    
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *buySelectedRateCell = @"YDBuySelectedRateCell";
    YDBuySelectedRateCell *cell = [tableView dequeueReusableCellWithIdentifier:buySelectedRateCell];
    if (cell == nil) {
        cell = [[YDBuySelectedRateCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:buySelectedRateCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.backgroundColor = [UIColor whiteColor];
        
        [self lineView];
        
        [self rateLabel];

        [self selectedImage];
        
    }
    return self;
}

-(UIView *)lineView
{
    if (_lineView == nil) {
        UIView *lineView = [[UIView alloc] init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = NumberColor(247, 247, 247);
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.height.equalTo(@1);
        }];
        _lineView = lineView;
    }
    return _lineView;
}
-(UILabel *)rateLabel
{
    if (_rateLabel == nil) {
        UILabel *rateLabel = [[UILabel alloc] init];
        [self.contentView addSubview:rateLabel];///104 114 132
        rateLabel.textColor = NumberColor(104, 114, 132);
        rateLabel.font = [UIFont systemFontOfSize:font16ScreenWRate * LKScreenW];
        rateLabel.textAlignment = NSTextAlignmentRight;
        rateLabel.text = @"";
        [rateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self).offset(rate375(27));
        }];
        _rateLabel = rateLabel;
    }
    return _rateLabel;
}
-(UIImageView *)selectedImage
{
    if (_selectedImage == nil) {
        UIImageView *selectedImage = [[UIImageView alloc] init];
        [self.contentView addSubview:selectedImage];
        selectedImage.image = [UIImage imageNamed:@"xialakuang-xuanzhong"];
        [selectedImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.right.equalTo(self).offset(-rate375(36));
        }];
        
        _selectedImage = selectedImage;
    }
    return _selectedImage;
}


@end
